<template>
    
  <div>
    <el-container>
      <el-header>
        <h1>电商后台管理系统</h1>
        <el-button type="info" @click="open">退出</el-button>
      </el-header>
      <el-container>
        <el-aside :width="isCollapse ? '64px' : '200px'">
          <div class="toggle" @click="toggleCollapse">|||</div>
          <el-menu
            :default-active="activePath"
            background-color="#545c64"
            text-color="#fff"
            active-text-color="#ffd04b"
            router
            :collapse="isCollapse"
            :unique-opened="true"
          >
            <el-submenu
              :index="item.id + ''"
              v-for="item in list"
              :key="item.id"
            >
              <template slot="title">
                <i :class="iconsObj[item.id]"></i>
                {{ item.authName }}
              </template>
              <el-menu-item-group
                v-for="index in item.children"
                :key="index.id"
              >
                <el-menu-item :index="'/' + index.path">
                  <i class="el-icon-menu"></i>
                  {{ index.authName }}
                </el-menu-item>
              </el-menu-item-group>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { menus } from "../../api/user";
export default {
  name: "",
  data() {
    return {
      list: [],
      activePath: "",
      iconsObj: {
        125: "iconfont icon-user",
        103: "iconfont icon-tijikongjian",
        101: "iconfont icon-shangpin",
        102: "iconfont icon-danju",
        145: "iconfont icon-baobiao",
      },
      isCollapse: false,
    };
  },
  created() {
    this.getMenusList();
    this.activePath = window.sessionStorage.getItem("activePath");
  },
  computed: {},
  methods: {
    //   退出
    open() {
      this.$confirm("您确认退出登录吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          window.sessionStorage.clear();
          this.$router.push("/login");
          this.$message({
            type: "success",
            message: "退出成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消退出",
          });
        });
    },
    //========================================================
    // 左侧菜单栏
    async getMenusList() {
      const { data: res } = await menus();
      // console.log(res);
      this.list = res.data;
    },
    toggleCollapse() {
      this.isCollapse = !this.isCollapse;
    },
  },
};
</script>

<style lang="scss" scoped>
.el-header,
.el-footer {
  background-color: rgb(55, 61, 65);
  color: #ffffff;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.el-aside {
  height: 100%;
  .toggle {
    background: #4a5064;
    font-size: 10px;
    line-height: 24px;
    color: #ffffff;
    text-align: center;
    letter-spacing: 0.2em;
    cursor: pointer;
  }
}

.el-main {
  background-color: #e9eef3;
  // color: #333;
  // text-align: center;
  // line-height: 160px;
}
</style>
